package com.example.cardgame

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.CheckBox
import android.widget.EditText
import android.widget.ImageView
import android.widget.RadioButton
import android.widget.RadioGroup
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class EditInfoActivity : AppCompatActivity() {
    private lateinit var genderGroup: RadioGroup
    private lateinit var hobbyReading: CheckBox
    private lateinit var hobbyTraveling: CheckBox
    private lateinit var hobbyGaming: CheckBox
    private lateinit var hobbyShopping:CheckBox
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_edit_info)

        val editName = findViewById<EditText>(R.id.editName)
        val editPhone = findViewById<EditText>(R.id.editPhone)
        val saveButton = findViewById<Button>(R.id.saveButton)
        val back=findViewById<Button>(R.id.back)
        val editStuno = findViewById<EditText>(R.id.editStuno)
        hobbyReading = findViewById(R.id.hobbyReading)
        hobbyTraveling = findViewById(R.id.hobbyTraveling)
        hobbyGaming = findViewById(R.id.hobbyGaming)
        hobbyShopping=findViewById(R.id.hobbyShopping)

        genderGroup = findViewById(R.id.genderGroup)


        saveButton.setOnClickListener {
            val selectedGenderId = genderGroup.checkedRadioButtonId
            val selectedGender = findViewById<RadioButton>(selectedGenderId).text.toString()

            val resultIntent = Intent()
            val hobbies = mutableListOf<String>()
            if (hobbyReading.isChecked) hobbies.add(getString(R.string.reading))
            if (hobbyTraveling.isChecked) hobbies.add(getString(R.string.traveling))
            if (hobbyGaming.isChecked) hobbies.add(getString(R.string.gaming))
            if (hobbyShopping.isChecked) hobbies.add(getString(R.string.shopping))
            resultIntent.putExtra("name", editName.text.toString())
            resultIntent.putExtra("gender",selectedGender)
            resultIntent.putExtra("stuno", editStuno.text.toString())
            resultIntent.putExtra("phone", editPhone.text.toString())
            resultIntent.putStringArrayListExtra("hobbies", ArrayList(hobbies))
            setResult(Activity.RESULT_OK, resultIntent)
            finish()
        }

        back.setOnClickListener{
            finish()
        }
    }
}